﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="User.aspx.cs" Inherits="WEB.APP.Modules.System.User" %>

<%@ Register Assembly="Ext.Net" Namespace="Ext.Net" TagPrefix="ext" %>
<%@ Register Src="~/Controls/System/UserForm.ascx" TagName="WindowEditor" TagPrefix="uc" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
    <script language="javascript" type="text/javascript">
        function DocumentReady() {
            MethodNamespace.DocumentReady({
                success: function() {

                }
            });
        }
    </script>

</head>
<body>
    <form id="form1" runat="server">
    <ext:Hidden runat="server" ID="hfIsEdit" />
    <ext:Hidden runat="server" ID="hfIsDelete" />
    <ext:Store ID="storeMain" runat="server" GroupField="RoleName" OnRefreshData="storeMain_OnRefreshData"
        WarningOnDirty="false">
        <Proxy>
            <ext:PageProxy />
        </Proxy>
        <Reader>
            <ext:JsonReader IDProperty="UserName">
                <Fields>
                    <ext:RecordField Name="UserName" />
                    <ext:RecordField Name="Password" />
                    <ext:RecordField Name="RoleId" />
                    <ext:RecordField Name="RoleName" />
                    <ext:RecordField Name="IsActive" />
                    <ext:RecordField Name="CreatedDate" />
                    <ext:RecordField Name="CreatedBy" />
                    <ext:RecordField Name="UpdatedDate" />
                    <ext:RecordField Name="UpdatedBy" />
                </Fields>
            </ext:JsonReader>
        </Reader>
        <BaseParams>
            <ext:Parameter Name="start" Value="0" Mode="Raw" />
            <ext:Parameter Name="limit" Value="50" Mode="Raw" />
        </BaseParams>
    </ext:Store>
    <ext:Viewport ID="Viewport1" runat="server" Layout="border">
        <Items>
            <ext:GridPanel ID="grdMain" runat="server" StripeRows="true" TrackMouseOver="true"
                AutoExpandColumn="UserName" Border="false" Region="Center" StoreID="storeMain">
                <TopBar>
                    <ext:Toolbar ID="tbMain" runat="server">
                        <Items>
                            <ext:ToolbarSpacer />
                            <ext:Button ID="btnAdd" runat="server" Text="New" Icon="TableAdd">
                                <DirectEvents>
                                    <Click OnEvent="btnAdd_Click" />
                                </DirectEvents>
                            </ext:Button>
                            <ext:ToolbarSpacer />
                            <ext:Button ID="btnDelete" runat="server" Text="Delete" Icon="TableDelete">
                                <Listeners>
                                    <Click Handler="deleteRows(#{grdMain});" />
                                </Listeners>
                            </ext:Button>
                            <ext:ToolbarFill />
                            <ext:TextField ID="txtKeyword" runat="server" EmptyText="Search">
                                <Listeners>
                                    <SpecialKey Handler="if(e.getKey() == Ext.EventObject.ENTER){storeMain.reload();}" />
                                </Listeners>
                            </ext:TextField>
                            <ext:ToolbarSpacer />
                            <ext:Button ID="btnFind" runat="server" Text="Search" Icon="Find" FormBind="true">
                                <Listeners>
                                    <Click Handler="storeMain.reload();" />
                                </Listeners>
                            </ext:Button>
                        </Items>
                    </ext:Toolbar>
                </TopBar>
                <ColumnModel ID="ColumnModel1" runat="server">
                    <Columns>
                        <ext:RowNumbererColumn />
                        <ext:Column ColumnID="UserName" DataIndex="UserName" Header="User Name" />
                        <ext:Column ColumnID="RoleName" DataIndex="RoleName" Header="Role" Width="200" />
                        <ext:CheckColumn Editable="true" ColumnID="IsActive" DataIndex="IsActive" Header="Active"
                            Align="Center" Width="80" />
                    </Columns>
                </ColumnModel>
                <KeyMap>
                    <ext:KeyBinding>
                        <Keys>
                            <ext:Key Code="DELETE" />
                        </Keys>
                        <Listeners>
                            <Event Handler="deleteRows(#{grdMain});" />
                        </Listeners>
                    </ext:KeyBinding>
                </KeyMap>
                <Listeners>
                    <BeforeEdit Handler="if (!hfIsEdit.value) {Ext.Msg.alert('Notification', 'You haven\'t permission edit!');return false;}return true;" />
                    <AfterEdit Handler="var id = e.grid.getColumnModel().getColumnId(e.column);
                                if (id === 'IsActive') {                                                                    
                                    var r = grdMain.selModel.grid.store.getAt(e.row);                                    
                                    MethodNamespace.grdMain_AfterEdit(r.data.UserName, e.value);
                                }" />
                    <RowDblClick Handler="this.getSelectionModel().selectRow(rowIndex); viewWinDetail(#{grdMain});" />
                    <RowContextMenu Handler="e.preventDefault(); #{RowContextMenu}.dataRecord = this.store.getAt(rowIndex);#{RowContextMenu}.showAt(e.getXY());this.getSelectionModel().selectRow(rowIndex);" />
                </Listeners>
                <DirectEvents>
                    <Command OnEvent="grdMain_OnCommand">
                        <ExtraParams>
                            <ext:Parameter Name="command" Value="command" Mode="Raw" />
                            <ext:Parameter Name="id" Value="record.data.UserName" Mode="Raw" />
                        </ExtraParams>
                        <Confirmation ConfirmRequest="true" Message="You really want to remove the lines data?"
                            Title="Notice" BeforeConfirm="if (command=='Edit') return false;" />
                    </Command>
                </DirectEvents>
                <SelectionModel>
                    <ext:RowSelectionModel ID="RowSelectionModel1" runat="server" SingleSelect="true" />
                </SelectionModel>
                <View>
                    <ext:GroupingView ID="GroupingView1" HideGroupedColumn="true" runat="server" EnableRowBody="true"
                        MarkDirty="false" GroupTextTpl="{[values.rs[0].data.RoleName]}">
                    </ext:GroupingView>
                </View>
                <BottomBar>
                    <ext:PagingToolbar ID="paddingBar" StoreID="storeMain" runat="server" PageSize="50"
                        DisplayInfo="true">
                    </ext:PagingToolbar>
                </BottomBar>
            </ext:GridPanel>
        </Items>
    </ext:Viewport>
    <uc:WindowEditor ID="WindowEditor" runat="server" />
    <ext:Menu ID="RowContextMenu" runat="server">
        <Items>
            <ext:MenuItem ID="mnDelete" runat="server" Text="Delete" Icon="Delete">
                <Listeners>
                    <Click Handler="deleteRows(#{grdMain});" />
                </Listeners>
            </ext:MenuItem>
            <ext:MenuItem ID="mnEdit" runat="server" Text="Edit" Icon="TableEdit">
                <Listeners>
                    <Click Handler="viewWinDetail(#{grdMain});" />
                </Listeners>
            </ext:MenuItem>
        </Items>
    </ext:Menu>
    </form>
</body>
</html>
